{template '_header'}

{template 'diypage/_common'}

<div class="page-heading">
    <span class="pull-right">
        <a class="btn btn-default btn-sm" href="{php echo $pagetype=='sys' ? webUrl('diypage/page/sys') : webUrl('diypage/page/diy')}"><i class="fa fa-reply"></i> 返回列表</a>
    </span>
    <h2><i class="fa fa-circle-o"></i>
        {if $do=='edit'}编辑{else}新建{/if} {$typename} {if $pagetype!='mod'}页面{/if}
        {if !empty($page)}
            <small>{if $do=='edit'}({if $pagetype=='mod'}模块{else}页面{/if}名称: {$page['name']}){elseif ($do=='add' && !empty($template) && !empty($template['data']))}(通过模板：{$template['name']} 创建){/if}</small>
        {/if}
    </h2>
</div>
<style>
.btn i {
    margin-right: 0px;
}
.diy-menu .navs nav {
    overflow: hidden;
}
.input-group>.btn{
	display:inline-block;
	height:auto;
	width:auto;
	padding:2px 20px;
	margin-top:10px;
	border: 1px solid #d2d2d2!important;
}
.input-group>.btn:hover{
	background-color:#d1d1d1;
	color:white;
}
.diy-menu .navs nav {
    color: #444;
	}
	.navs .special{
		display:inline-block;
	}
</style>
<div class="diy-phone" data-merch="{php echo intval($_W['merchid'])}">
    <div class="phone-head"></div>
    <div class="phone-body">
        <div class="phone-title" id="page">loading...</div>
        <div class="phone-main" id="phone">
            <p style="text-align: center; line-height: 400px">您还没有添加任何元素</p>
        </div>
    </div>
    <div class="phone-foot"></div>
</div>

<div class="diy-editor form-horizontal" id="diy-editor">
    <div class="editor-arrow"></div>
    <div class="inner"></div>
</div>

<div class="diy-menu">
    <div class="navs" id="navs">
	</div>
    <div class="action">
        <nav class="btn btn-default btn-sm" style="float: left; display: none" id="gotop"><i class="icon icon-top" style="font-size: 12px"></i> 返回顶部</nav>
        {if $pagetype=='sys'}
            {ifp 'diypage.page.sys.savetemp'}
                <nav class="btn btn-warning btn-sm btn-save" data-type="savetemp">另存为模板</nav>
            {/if}
        {/if}
        {if $pagetype=='diy'}
            {ifp 'diypage.page.diy.savetemp'}
                <nav class="btn btn-warning btn-sm btn-save" data-type="savetemp">另存为模板</nav>
            {/if}
        {/if}
        {if $pagetype=='plu'}
            {ifp 'diypage.page.plu.savetemp'}
                <nav class="btn btn-warning btn-sm btn-save" data-type="savetemp">另存为模板</nav>
            {/if}
        {/if}
        <nav class="btn btn-primary btn-sm btn-save" data-type="save">保存{if $pagetype=='mod'}模块{else}页面{/if}</nav>
        {if $pagetype=='sys' || $pagetype=='diy' || $pagetype=='plu'}
            {if $_GPC['type']!=5 && $page['type']!=5 && $_GPC['type']!=7 && $page['type']!=7 && $_GPC['type']!=8 && $page['type']!=8}
                <nav class="btn btn-success btn-sm btn-save" data-type="preview">保存并预览</nav>
            {/if}
        {/if}
    </div>
</div>

{template 'diypage/_template'}
{template 'diypage/_template_edit'}

<script type="text/javascript" src="./resource/components/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="./resource/components/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="./resource/components/ueditor/lang/zh-cn/zh-cn.js"></script>

<script language="javascript">
    var path = '../../plugin/diypage/static/js/diy.min';
    myrequire([path,'tpl','web/biz'],function(modal,tpl){
        modal.init({
            tpl: tpl,
            attachurl: "{$_W['attachurl']}",
            id: '{php echo intval($_GPC["id"])}',
            type: {$type},
            data: {if !empty($page['data'])}{php echo json_encode($page['data'])}{else}null{/if},
            diymenu: {php echo json_encode($diymenu)},
            levels: {if !empty($levels)}{php echo json_encode($levels)}{else}null{/if},
            merch: {if $_W['plugin']=='merch' && !empty($_W['merchid'])}1{else}0{/if},
            plugins: {$hasplugins},
            shopset: {php echo json_encode($_W['shopset']['shop'])}
        });
    });
    function selectUrlCallback(href){
        var ue =  UE.getEditor('rich');
        if(href){
            ue.execCommand('link', {href: href, 'data-nocache': 'true'});
        }
    }
    function callbackGoods(data) {
        myrequire([path],function(modal) {
            modal.callbackGoods(data);
        });
    }
    function callbackCategory (data) {
        myrequire([path],function(modal) {
            modal.callbackCategory(data);
        });
    }
    function callbackGroup (data) {
        myrequire([path],function(modal) {
            modal.callbackGroup(data);
        });
    }
    function callbackMerch (data) {
        myrequire([path],function(modal) {
            modal.callbackMerch(data);
        });
    }
    function callbackMerchCategory (data) {
        myrequire([path],function(modal) {
            modal.callbackMerchCategory(data);
        });
    }
    function callbackMerchGroup (data) {
        myrequire([path],function(modal) {
            modal.callbackMerchGroup(data);
        });
    }
    function callbackSeckill (data) {
        myrequire([path],function(modal) {
            modal.callbackSeckill(data);
        });
    }
    function callbackCoupon (data) {
        myrequire([path],function(modal) {
            modal.callbackCoupon(data);
        });
    }
</script>

{template '_footer'}